﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace FITHOU_EDU_Server
{
    public partial class getMaxKy : System.Web.UI.Page
    {
        String sqlCon = ConfigurationManager.ConnectionStrings["FITHOU_EDU"].ToString();
        string sUserName;
        protected void Page_Load(object sender, EventArgs e)
        {
            layky();
        }

        private void layky()
        {
            int ky = 0;
            
            sUserName = Request.QueryString["sUserName"];
            if (sUserName == null) sUserName = "";

            if (sUserName == null)
            {
                Response.Write("Thông số kết nối tới serrver không chính xác, vui lòng kiểm tra lại.");
                return;
            }

            SqlConnection Con = new SqlConnection(sqlCon);
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter adapter = null;
            DataTable tbl = new DataTable();
            try
            {
                
                Con.Open();
                cmd.CommandText = "getmaxky";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = Con;
                cmd.Parameters.Add("@FK_sSinhVienID", SqlDbType.VarChar);
                try
                {
                    cmd.Parameters[0].Value = sUserName;
                }
                catch (Exception e)
                {
                    Response.Write("0");
                }


               
                adapter = new SqlDataAdapter(cmd);
                adapter.Fill(tbl);
              
                if (tbl.Rows.Count > 0)
                {
                    Response.Write(tbl.Rows[0][0].ToString());
                }           
                
                


            }catch(Exception e)
            {
                Response.Write("0");
            }


           // return ky;
        }
    }
}